// pages/newindex/newindex.js
var util = require('../../utils/util')   //引入配置公共请求接口
var configUrl = require('../../config/config')  //引入配置接口文件
const app=getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    topFixed: false,
    bgimgUrl: getApp().globalData.BgimgUrl,
    logoImg: getApp().globalData.BgimgUrl + 'logoImg.png', // logo
    headBgimg: '', // 头部背景图
    seckillBgimg: '' , // 秒杀模块背景图
    hotmoneyBgimg: '', // 尖货爆款背景图
    nearbyStoresIcon: getApp().globalData.BgimgUrl + 'nearbyStoresIcon.png', // 附近门店图标
    nearbyStoresImg: getApp().globalData.BgimgUrl + 'nearbyStoresImg.png', // 附近门店图片
    wholeCustomIcon: getApp().globalData.BgimgUrl + 'wholeCustomIcon.png', // 全屋定制图标
    guessLikeIcon: getApp().globalData.BgimgUrl + 'guessLikeIcon.png', // 猜你喜欢图标
    seckillsubColor: '#00AE97',
    hotmoneyData: [{name: '尖货爆款', id: 0, sub: '精选好货推荐'}, {name: '新品首发', id: 1, sub: '新品追潮流'}],
    hotSelect: 0,
    hotColor: {
      subTitleFontColor: "",
      subTitleSelectFontBgColor: "",
      subTitleSelectFontColor: "",
      titleFontColor: "",
    },
    foundData: [{name: '精选案例', id: 0, sub: '设计源于灵感'}, {name: '家居百科', id: 1, sub: '装修百科全书'}, {name: '友家秀', id: 2, sub: '发现真实好家'}],
    foundSelect: 0,
    img:getApp().globalData.img,
    imgUrl:getApp().globalData.imgUrl,
    cardCur: 0,
    carGoods:0,  //购物车商品数
    thisAddress:'',
    isToBack:false,
    endTime: "2020-09-14 14:55:00",                                   // 设置结束时间
    timer: "",                                                     // 倒计时定时器名称
    countDown: { day : "00", hour: "00", min: "00", sec: "00" },     // 秒杀倒计时
    active: 0,
    navCur: 0,
    isShowGetUserInfo:false,
    canIUse: wx.canIUse('button.open-type.getUserInfo'),
    navlist:[],
    swiperList: [],
    disposeList: [],
    selectedData: [], // 精选专区
    newProductData: [], // 新品首发
    houseProductData: [], // 全屋定制
    seckillData: [], // 秒杀
    sliderData: [], // 轮播
    bannerData: [], // 广告
    recommendList: [], // 精选案例
    encyclopediaData: [], // 家居百科
    showData: [], // 友家秀
    guessYouLikeData: [], // 猜你喜欢
    addrCode: {},
    loading: false,
    spaceImg: '', // 全屋特惠空间展示图片
    appSmsActivities: '',
        /**-合伙人--*/
        isShowPartnerAll: 1,
        showPartnerCodePop:false,
        // 获取手机号
        getPhoneNumberData:{
          isShowGetPhoneNumber:false

        }
  },

  setNavHeight:function(){
    const sysInfo = wx.getSystemInfoSync()
    const statusHeight = sysInfo.statusBarHeight
    this.setData({
      statusHeight
    })
  },

// 商品推荐选项
  tabHot(data) {
    const id = data.currentTarget.dataset.data.id
    this.setData({
      hotSelect: id
    })
  },
  // 友发现选项
  tabFound(data) {
    const id = data.currentTarget.dataset.data.id
    // if (id == 1) {
    //   this.homeEncyclopedia()
    // } else if(id == 2) {
    //   this.getshouwData()
    // }
    this.setData({
      foundSelect: id
    })
  },

  navSelect(e) {
    this.setData({
      navCur: e.currentTarget.dataset.id,
     })
     let navlist = this.data.navlist
    for(var i = 0, len = navlist.length; i < len; i++) {
      if (e.currentTarget.dataset.id == navlist[i].id) {
        this.setData({
          spaceImg: navlist[i].pics[0].picturePath,
         })
      }
    }
  },
  onClick(event) {
    wx.showToast({
      title: `点击标签 ${event.detail + 1}`,
      icon: 'none',
    });
  },
  /**绑定手机号 ---str*/
  closeGetphone(){
    this.setData({
      getPhoneNumberData:{
        isShowGetPhoneNumber:false

      }
    })
  },
  getPhoneNumber(e){
    let loginMsg = wx.getStorageSync('loginMsg')
    if (e.detail.iv && e.detail.encryptedData) {
      let option = {}
      option.encryptedData = e.detail.encryptedData
      option.iv = e.detail.iv
      option.openid = loginMsg.openid
      option.session_key = loginMsg.session_key
      app.reqFun.requestJson('POST',configUrl.decryptGetPhone,option,(res)=>{
        if(res.data.success==1){
          this.setData({
            getPhoneNumberData:{
              isShowGetPhoneNumber:false
            }
          })
          wx.showToast({
            title: '绑定成功。',
          })
        }
      })
    } else {
      console.log('取消')
    }
  },
  /**  end
   *  绑定手机号
   */
  onChange(e) {
    this.setData({
      timeData: e.detail,
    });
  },
  // 监听页面滚动距离scrollTop
onPageScroll: function(e) {
  var that = this;
  // 3.当页面滚动距离scrollTop > 菜单栏距离文档顶部的距离时，菜单栏固定定位
  if (e.scrollTop > 30) {
    that.setData({
      topFixed: true
    })
  } else {
    that.setData({
      topFixed: false
    })
  }
},
  goSearchPage(e){   //商品搜索进入商品列表
    // this.getLogin((re)=>{
    //   if(re){
        wx.navigateTo({
          url: '/packageShop/pages/shopSearch/shopSearch?type=s',
        })
    //   }
    // })
  },
  goClassify(e){  //进入分类
    // this.getLogin((re)=>{
    //   if(re){
      wx.navigateTo({
        url: '/pages/classify/classify',
      })
  //   }
  // })
  },
goevalInfo(e){  //临时链接跳转 评价详情
  // this.getLogin((re)=>{
  //   if(re){
    let urltype = e.currentTarget.dataset.data.linkUrlType
    let url = e.currentTarget.dataset.data.linkUrl
    let id = e.currentTarget.dataset.data.activityPageId
    let activityUrl = '/packagBuy/pages/marketing/activityPage/activityPage' + '?id=' + id
    if (urltype == 'miniPage') {
      wx.navigateTo({
        url: url
      })
    } else if(urltype == 'h5' && url!== '/packagBuy/pages/found/crmweb/index') {
      wx.navigateTo({
        url: '/packagBuy/pages/marketing/poster/posterh5/posterh5?h5Url=' + url
      })
    } else if(url == '/packagBuy/pages/found/crmweb/index') {
      wx.navigateTo({
        url: '/packagBuy/pages/found/crmweb/index'
      })
    } else {
      wx.navigateTo({
        url: activityUrl
      })
    }
//   }
// })
},
 /**
 * 生命周期函数--监听页面加载
 */
onLoad: function (options) {
  console.log('options', options)
  let that=this
  //获取设置，用于判断是否在小程序内(可能有更好的判断方法)
  wx.getSetting({
    success (res){
      console.log('小程序内', res)
      that.setNavHeight()
      that.getTopTheme()
      that.getSeckillTheme()
      that.getUserLocation((res2)=>{
        console.log('首页位置', res2)
        if(res2.getSetting){
          that.setData({
            showSetting:true,
            getPhoneNumberData:{
              isShowGetPhoneNumber:false
            }
          })
        }else{
          // var addressInfo=res.addressComponent
          // that.setData({
          //   thisAddress:addressInfo.city
          // })
        }
      })
      let addrCode = wx.getStorageSync('addrCode')
      that.setData({
        addrCode: addrCode
      })
      wx.removeStorageSync('selectAddId')
      wx.removeStorageSync('nowBuyDepositSku')
      if (options && (options.scene||options.hid)) {
        var scene = options.hid?options.hid:decodeURIComponent(options.scene) //参数二维码传递过来的参数
        if(options.hid){
          var stInFun = setInterval(() => {
            if (wx.getStorageSync('loginMsg').token && wx.getStorageSync('addrCode').provinceCode) {
              clearInterval(stInFun)
              if (!wx.getStorageSync('loginMsg').loginState) {
                if (wx.getUserProfile) {
                  app.getUserProfile(function(){
                    that.setData({
                      getPhoneNumberData:{
                        isShowGetPhoneNumber:true
                      }
                    })
                  })
                } else {
                  if(!wx.getStorageSync('loginMsg').bindingPhone){
                    that.setData({
                      getPhoneNumberData:{
                        isShowGetPhoneNumber:true
                      }
                    })
                  }
                }
                // that.setData({
                //   isShowGetUserInfo: true
                // })
              }
              app.bindingPartner(options.hid)
              that.getPartnerInfo(options.hid)
            }
          }, 500)
        }else{
          app.getShareCode(scene, (res) => {
            var stInFun = setInterval(() => {
              if (wx.getStorageSync('loginMsg').token && wx.getStorageSync('addrCode').provinceCode) {
                clearInterval(stInFun)
                if (!wx.getStorageSync('loginMsg').loginState) {
                  if (wx.getUserProfile) {
                    app.getUserProfile(function(){
                      that.setData({
                        getPhoneNumberData:{
                          isShowGetPhoneNumber:true
                        }
                      })
                    })
                  } else {
                    if(!wx.getStorageSync('loginMsg').bindingPhone){
                      that.setData({
                        getPhoneNumberData:{
                          isShowGetPhoneNumber:true
                        }
                      })
                    }
                  }
                  // that.setData({
                  //   isShowGetUserInfo: true
                  // })
                }
                app.bindingPartner(res.userId)
                that.getPartnerInfo(res.userId)
              }
            }, 500)
          })
        }
      }
      that.getmmsPosterPage()
      // that.getRecommendList()
    },
    fail(res) {
      //拿不到设置，视为微信朋友圈单页
      console.log('获取设置失败', res)
      console.log('单页内')
      let pricePstCode = undefined
      let cityCode = undefined
      that.setNavHeight()
      that.getTopTheme()
      that.getSeckillTheme()
      that.getmmsPosterPage()
      // that.getRecommendList()
      that.getHomeBanner(pricePstCode)
      that.getselectedProduct('HOT', pricePstCode)
      that.getselectedProduct('NEW', pricePstCode)
      that.getselectedProduct('HOUSE', pricePstCode)
      that.getmmsSeckillcurrent(pricePstCode)
      that.getBanner('mini_home_slider_up', cityCode)
      that.getBanner('mini_home_slider_down', cityCode)
      that.getGuessYouLike(pricePstCode)
    }
  })
},
   //获取用户地理位置
getUserLocation:function(callback){
  let that = this
  console.log('首页定位')
  if (wx.getStorageSync('getLocation') === 'Y') {
    console.log('首页等待appJs定位完成')
    var setGetLocation=setInterval(()=> {
      if (wx.getStorageSync('getLocation') === 'N') {
        that.setData({
          thisAddress: '青羊区'
        })
        that.getHomeBanner('510000000000');
        that.getselectedProduct('HOT', '510000000000')
        that.getselectedProduct('NEW', '510000000000')
        that.getselectedProduct('HOUSE', '510000000000')
        that.getBanner('mini_home_slider_up', '510100000000')
        that.getBanner('mini_home_slider_down', '510100000000')
        callback({
          'showSetting':true,
          'getSetting':true
        })
        clearInterval(setGetLocation)
      }
      if (wx.getStorageSync('locationInfo')) {
        let res = wx.getStorageSync('locationInfo')
        const latitude = res.latitude
        const longitude = res.longitude
        var laorln=util.qqMapTransBMap(latitude,longitude)
        wx.setStorageSync('latAndLong', laorln)
        var parms={latitude:laorln.latitude,longitude:laorln.longitude}
        app.reqFun.requestJson('get',configUrl.getAddrCode,parms,(res)=> {
          if (res.data.success==1) {
            wx.setStorageSync('addrCode', res.data.data)
            let pricePstCode = res.data.data.pricePstCode
            let cityCode = res.data.data.cityCode
            let address = res.data.data.province + res.data.data.city + res.data.data.district + res.data.data.street + res.data.data.townName + res.data.data.streetNumber
            that.getHomeBanner(pricePstCode)
            that.getselectedProduct('HOT', pricePstCode)
            that.getselectedProduct('NEW', pricePstCode)
            that.getselectedProduct('HOUSE', pricePstCode)
            that.getmmsSeckillcurrent(pricePstCode)
            that.getBanner('mini_home_slider_up', cityCode)
            that.getBanner('mini_home_slider_down', cityCode)
            that.getGuessYouLike(pricePstCode)
            that.getnearby(address)
            that.setData({
              thisAddress: res.data.data.city
            })
          }
        })
        clearInterval(setGetLocation)
      }
    },1000)
    return
  }
  wx.getSetting({
    success (res){
      if (res.authSetting['scope.userLocation'] !=false) {
        wx.getLocation({
          type: 'wgs84',
          success (res) {
            const latitude = res.latitude
            const longitude = res.longitude
            var laorln=util.qqMapTransBMap(latitude,longitude)
            wx.setStorageSync('latAndLong', laorln)
            var parms={latitude:laorln.latitude,longitude:laorln.longitude}
            app.reqFun.requestJson('get',configUrl.getAddrCode,parms,(res)=>{
              if(res.data.success==1){
                wx.setStorageSync('addrCode', res.data.data)
                let pricePstCode = res.data.data.pricePstCode
                let cityCode = res.data.data.cityCode
                let address = res.data.data.province + res.data.data.city + res.data.data.district + res.data.data.street + res.data.data.townName + res.data.data.streetNumber
                that.getHomeBanner(pricePstCode)
                that.getselectedProduct('HOT', pricePstCode)
                that.getselectedProduct('NEW', pricePstCode)
                that.getselectedProduct('HOUSE', pricePstCode)
                that.getmmsSeckillcurrent(pricePstCode)
                that.getBanner('mini_home_slider_up', cityCode)
                that.getBanner('mini_home_slider_down', cityCode)
                that.getGuessYouLike(pricePstCode)
                that.getnearby(address)
                that.setData({
                  thisAddress: res.data.data.city
                })
              }
            })
          },fail(res){
            that.setData({
              thisAddress: '青羊区'
            })
            that.getHomeBanner('510000000000');
            that.getselectedProduct('HOT', '510000000000')
            that.getselectedProduct('NEW', '510000000000')
            that.getselectedProduct('HOUSE', '510000000000')
            that.getBanner('mini_home_slider_up', '510100000000')
            that.getBanner('mini_home_slider_down', '510100000000')
            callback({
              'showSetting':true,
              'getSetting':true
            })
          }
        })
      }else{
        that.setData({
          thisAddress: '青羊区'
        })
        that.getHomeBanner('510000000000');
        that.getselectedProduct('HOT', '510000000000')
        that.getselectedProduct('NEW', '510000000000')
        that.getselectedProduct('HOUSE', '510000000000')
        that.getBanner('mini_home_slider_up', '510100000000')
        that.getBanner('mini_home_slider_down', '510100000000')
        callback({
          'showSetting':true,
          'getSetting':true
        })

      }
    },
  })
},
/**
 * 秒杀倒计时
 */
 countDown:function(){
  let that = this;
      that.setData({
        timer: setInterval(function(){
           var lefttime = parseInt((new Date(that.data.endTime.replace(/-/g,"/")).getTime() - new Date().getTime()));
           if(lefttime <= 0) {
             that.setData({
              countDown:{day:"00",hour:"00",min:"00",sec:"00"}
             })
             clearInterval(that.data.timer);
             return;
           }

           var d = parseInt(lefttime /1000 /3600 /24);  //天数
           var h = parseInt(lefttime / 1000 / 3600 % 24); //小时
           var m = parseInt(lefttime / 1000 / 60 % 60);    //分钟
           var s = parseInt(lefttime / 1000  % 60);        //当前的秒

           d < 10 ? d = "0" + d : d;
           h < 10 ? h = "0" + h : h;
           m < 10 ? m = "0" + m : m;
           s < 10 ? s = "0" + s : s;

           that.setData({
            countDown:{ day: d, hour: h, min: m, sec:s }
           })
        },1000)
      })
 },

 goodsInfo(option) {
    // this.getLogin((re)=>{
    //   if(re){
      let skuid = option.currentTarget.dataset.skuid
      wx.navigateTo({
        url: '/packageShop/pages/goodsInfo/goodsInfo?id=' + skuid,
      })
  //   }
  // })
 },
/**
 * 生命周期函数--监听页面初次渲染完成
 */
onReady: function () {
  this.homeEncyclopedia()
  this.getshouwData()
},

/**
 * 生命周期函数--监听页面显示
 */
onShow: function () {
  var that=this
  if(that.data.isToBack){  //处理页面加载时获取地址还是页面返回
    that.setData({
      isToBack:false
    })
    that.onLoad()
  }
},

/**
 * 生命周期函数--监听页面隐藏
 */
onHide: function () {
  this.setData({
    isToBack:true
  })
},

/**
 * 生命周期函数--监听页面卸载
 */
onUnload: function () {

},

/**
 * 页面相关事件处理函数--监听用户下拉动作
 */
onPullDownRefresh: function () {
  let that = this
  let addrCode = wx.getStorageSync('addrCode')
  let pricePstCode = addrCode.pricePstCode
  let cityCode = addrCode.cityCode
  console.log('addrCode', addrCode)
  wx.showNavigationBarLoading()
  that.getHomeBanner(pricePstCode)
  that.getselectedProduct('HOT', pricePstCode)
  that.getselectedProduct('NEW', pricePstCode)
  that.getselectedProduct('HOUSE', pricePstCode)
  that.getmmsSeckillcurrent(pricePstCode)
  that.getBanner('mini_home_slider_up', cityCode)
  that.getBanner('mini_home_slider_down', cityCode)
  that.getGuessYouLike(pricePstCode)
  wx.stopPullDownRefresh()

},

/**
 * 页面上拉触底事件的处理函数
 */
onReachBottom: function () {

},
bindGetUserInfo:function(e){  //登录-注册
  var that=this;
  var setFun=setInterval(()=>{
    if(wx.getStorageSync('showGetPhone')){
      that.setData({
        getPhoneNumberData:{
          isShowGetPhoneNumber:true
        }
      })
      wx.removeStorageSync('showGetPhone')
      clearInterval(setFun)
    }
  },1000)
  app.getUserInfo()
},
onCloseShowGetUserInfo(){  //关闭弹出层
  this.setData({
    showSetting:false,
    isShowGetUserInfo:false
  })
},
getHomeBanner(pricePstCode){ //首页数据（banner，dispose，Activities）
  let option = {
    'provinceAddrCode' : pricePstCode
  }
  this.getCarGoodsNumber()
  app.reqFun.requestJson('POST',configUrl.getHomePage,option,(res)=>{
    if(res.data.success==1){
      var list=res.data.data.appSmsHomeAdvertiseDTOList
      let spaceInfo = res.data.data.appSmsActivitiesDTO

      list.forEach( ( item, i ) => {
        item.id=i
      })
      this.setData({
        swiperList:list,     //轮播banner数据
        disposeList:res.data.data.appSmsHomeModelsDTOList,  //首页导航配置
        appSmsActivities:res.data.data.appSmsActivitiesDTO,   //活动数据
      })
      console.log('appSmsActivities', this.data.appSmsActivities)
      this.getHotTheme()
      if (spaceInfo && spaceInfo.spaceInfo) {
        let spaceInfo = res.data.data.appSmsActivitiesDTO.spaceInfo
        spaceInfo.forEach( ( item, i ) => {
          item.id=i
        })
        this.setData({
          navlist: spaceInfo,
          spaceImg: spaceInfo[0].pics[0].picturePath,
        })
      }
    }else{
      wx.showToast({
        icon:'none',
        title: res.data.msg,
      })
    }
  })
},
// 精选/新品专区
getselectedProduct(type, pricePstCode) {
  let that = this
  let option = {}
  option.page = 1
  if (type == 'HOT') {
    option.rows = 3
  } else {
    option.rows = 4
  }
  option.callFrom = type
  option.provinceCode = pricePstCode
  app.reqFun.requestJson('POST',configUrl.smsHomeNewProduct,option,(res)=>{
    if(res.data.success==1){
      let records = res.data.data.solrProductDtos.records
      if (type == 'HOT') {
        that.setData({
          selectedData: records
        })
      } else if(type == 'NEW') {
        this.setData({
          newProductData: records
        })
      } else {
        this.setData({
          houseProductData: records
        })
      }
    }
  })
},
// 获取海报类型
getmmsPosterPage() {
  let that = this
  app.reqFun.requestForm('GET',configUrl.mmsPosterPage + '/hotProduct','',(res)=>{
    if(res.data && res.data.success==1){
      let records = (res.data &&  res.data.data) || []
      that.setData({
        sortData: records[0]
      })
    }
  })
},
 // 跳转到海报配置页面
 pageJump(e){
  const data=e.currentTarget.dataset.data
  let urltype = data.urlType
  let url =data.url
  let activityPageId = data.activityPageId

  if (urltype == 'h5') {
    wx.navigateTo({
      url: '/packagBuy/pages/marketing/poster/posterh5/posterh5?h5Url=' + url
    })
  } else if(urltype == 'activityPage') {
    wx.navigateTo({
      url: '/packagBuy/pages/marketing/activityPage/activityPage?id=' + activityPageId,
    })
  } else {
    wx.navigateTo({
      url: url
    })
  }
},
// 秒杀
getmmsSeckillcurrent(pricePstCode) {
  let that = this
  let code = pricePstCode
  let formdata = {}
  formdata.page = 1
  formdata.rows = 6
  let mmsSeckillIndexUrl = configUrl.mmsSeckillIndex + '/' + code
  app.reqFun.requestForm('POST',mmsSeckillIndexUrl,formdata,(res)=>{
    if(res.data.success==1 && res.data.data){
      let data = res.data.data
      if (data.products) {
        let records = res.data.data.products
        that.setData({
          seckillData: records,
          endTime: res.data.data.endTime
        })
        that.countDown()
      }
    }
  })
},
 // 轮播/广告图
 getBanner(type, cityCode) {
  let that = this
  // let cityCode = cityCode
  let code = type
  let queryMiniByCodeUrl = configUrl.queryMiniByCode + '?cityCode=' + cityCode + '&code=' + code
  app.reqFun.requestJson('GET',queryMiniByCodeUrl,'',(res)=>{
    if(res.data.success==1){
      let records = res.data.data.pmsAdvertisementDTOList
      if (type == 'mini_home_slider_up') {
        that.setData({
          sliderData: records
        })
      } else {
        that.setData({
          bannerData: records
        })
      }
    }
  })
},

getnearby(data) { //获取附近门店---地址换取经纬度
  var that = this;
  var parms = {
    address: data
  }
  app.reqFun.requestJson('get', configUrl.geocode, parms, (res) => {
    if (res.data.success == 1) {
      that.nearbyShop(res.data.data.latitude, res.data.data.longitude)
    }
  })
},
nearbyShop(lat, long) { //经纬度获取附近门店   distance范围 latitude纬度   longitude 经度
  var that = this;
  var parms = {
    distance: 100000,
    latitude: lat,
    longitude: long
  }
  app.reqFun.requestJson('get', configUrl.nearbyShop, parms, (res) => {
    if (res.data.success == 1) {
      if (res.data.data) {
        if (res.data.data.length > 0) {
          that.setData({
            nowShowNearby: res.data.data[0]
          })
        } else {
          that.setData({
            nowShowNearby: ''
          })
        }
      } else {
        that.setData({
          nowShowNearby: ''
        })
      }
    } else {
      that.setData({
        nowShowNearby: ''
      })
    }
  }, true)
},

browsePage(e) {
  // console.log('e1111', e)
  // this.getLogin((re)=>{
  //   if(re){
    let urltype = e.currentTarget.dataset.data.linkUrlType
    let url = e.currentTarget.dataset.data.linkUrl
    let id = e.currentTarget.dataset.data.activityPageId
    let activityUrl = '/packagBuy/pages/marketing/activityPage/activityPage' + '?id=' + id
    if (urltype == 'miniPage') {
      wx.navigateTo({
        url: url
      })
    } else if(urltype == 'h5' && url!== '/packagBuy/pages/found/crmweb/index') {
      wx.navigateTo({
        url: '/packagBuy/pages/marketing/poster/posterh5/posterh5?h5Url=' + url
      })
    } else if(url == '/packagBuy/pages/found/crmweb/index') {
      wx.navigateTo({
        url: '/packagBuy/pages/found/crmweb/index'
      })
    } else {
      wx.navigateTo({
        url: activityUrl
      })
    }
  // }
  // })
},
 getGuessYouLike(pricePstCode) {
  let that = this
  that.setData({
    loading: true
  })
  let option = {}
  option.page = 1
  option.rows = 20
  option.provinceCode = pricePstCode
  option.sort = 'sort_pv_desc'
  option.groupField = 'product_id'
  option.groupSort = 'sort_pv_desc'
  option.callFrom = 'GUESS'
  app.reqFun.requestJson('POST',configUrl.guessYouLike,option,(res)=>{
    if(res.data.success==1){
      let records = res.data.data.solrProductDtos.records
      that.setData({
        guessYouLikeData: records
      })
      that.setData({
        loading: false
      })
    }
  })
},
goSeckill() {
  // this.getLogin((re)=>{
  //   if(re){
    wx.navigateTo({
      url: '/packagBuy/pages/marketing/seckill/seckill'
    })
//   }
// })
},
goSelected() {
  // this.getLogin((re)=>{
  //   if(re){
    wx.navigateTo({
      url: '/packagBuy/pages/marketing/selected/selected'
    })
//   }
// })
},
goNewProduct() {
  // this.getLogin((re)=>{
  //   if(re){
    wx.navigateTo({
      url: '/packagBuy/pages/marketing/newProduct/newProduct'
    })
//   }
// })
},
goWholehouse() {
  // this.getLogin((re)=>{
  //   if(re){
    wx.navigateTo({
      url: '/packagBuy/pages/marketing/wholehouse/index/index'
    })
//   }
// })
},
gowholehoseDetail() {
  // this.getLogin((re)=>{
  //   if(re){
    let activityId = this.data.appSmsActivities.activityId
    let id = this.data.appSmsActivities.mealId
    let option = {
      activityId: activityId,
      id: id
    }
    console.log('option', option)
    wx.navigateTo({
      url: '/packagBuy/pages/marketing/wholehouse/details/details?option=' + JSON.stringify(option),
    })
//   }
// })
},
getCarGoodsNumber() { //查询购物车商品数-
  var that = this;
  app.reqFun.requestJson('POST', configUrl.getCarNumber, '', (res) => {
    if (res.data.success == 1) {
      that.setData({
        carGoods: res.data.data
      })
    }
  }, true)
},
    /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    wx.showShareMenu({
      withShareTicket: true,
      menus: ['shareAppMessage', 'shareTimeline']
    })
    return {
      title: '全友家居官方商城',
      desc: '全友家居官方商城',
      path: '/pages/newIndex/newIndex?hid=' + wx.getStorageSync('loginMsg').userId
    }
  },

  //用户点击右上角分享朋友圈
  onShareTimeline: function () {
    let queryParam = 'hid=' + wx.getStorageSync('loginMsg').userId
    return {
      title: '全友家居官方商城',
      query: queryParam,
      imageUrl: ''
    }
  },

  //获取合伙人信息
  getPartnerInfo:function(userId){
    console.log('获取合伙人信息')
    console.log(userId)
    let that = this;
    app.reqFun.requestJson('get', configUrl.getPartnerInfo + userId, '', (res) => {
      console.log(res.data)
      if (res.data.success == 1) {
        var partnerInfo={
          id:wx.getStorageSync('loginMsg').userId,
          partnerNickName:res.data.data.partnerNickName,
          partnerPhone:res.data.data.partnerPhone,
          partnerPhoto:res.data.data.partnerPhoto,
          partnerQrCode:res.data.data.partnerQrCode,
        }
        that.setData({
          partnerInfo: partnerInfo
        })
      }
    }, true)
  },
  //展开合伙人信息
  showPartnerAll: function () {
    let isShowPartnerAll;
    if (this.data.isShowPartnerAll == 1) {
      isShowPartnerAll = 0;
    } else {
      isShowPartnerAll = 1;
    }
    this.setData({
      isShowPartnerAll: isShowPartnerAll,
    })
  },
  //展示合伙人二维码
  partnerCode:function(e){
    //  this.setData({
    //   showPartnerCodePop: true,
    // })
    let codeImg=e.target.dataset.url
    wx.previewImage({
      urls:[codeImg],
      current: codeImg, // 当前显示图片的http链接
     })
  },
   //关闭合伙人二维码
  closeCodePop:function(){
    console.log("3253456678dsgudkdkgfksfvkjdsvbjkdsvbvkj")
    this.setData({
      showPartnerCodePop: false,
    })
  },
  //拨打合伙人电话
  partnerPhone:function(){
    let that = this;
    wx.makePhoneCall({
      phoneNumber: that.data.partnerInfo.partnerPhone,
    })
  },
  // 跳转附近门店
  nearbyStores() {
    wx.navigateTo({
      url: '/packageShop/pages/nearbyStores/nearbyStores'
    })
  },
  // 获取推荐
  getRecommendList() {
    let that = this
    app.reqFun.requestJson('GET',configUrl.foundApi.getRecommendList,'',(res)=>{
      if(res.data.success==1){
        this.setData({
          recommendList: res.data.data
        })
        console.log('recommendList', that.data.recommendList)
      }
    })
  },
  // 家居百科
  homeEncyclopedia() {
    console.log('点击选')
    app.reqFun.requestForm('GET', configUrl.queryByContentType+`/${2}/${10}`, '', (res) => {
      if (res.data.success == 1) {
        let records = res.data.data.records
        this.setData({
          encyclopediaData: records,
        })
      }
    })
  },
  // 友家秀
  getshouwData() {
    app.reqFun.requestForm('GET', configUrl.queryByContentType+`/${3}/${10}`, '', (res) => {
      if (res.data.success == 1) {
        let records = res.data.data.records
        this.setData({
          showData: records,
        })
      }
    })
  },
  foundMore() {
    if (this.data.foundSelect == 1) {
      wx.navigateTo({
        url: '/packagBuy/pages/found/encyclopedia/encyclopedia'//家居百科
      })
    } else if (this.data.foundSelect == 2) {
      wx.navigateTo({
        url: '/packagBuy/pages/found/show/show'//友家秀
      })
    } else {
      this.goMeita()
    }
  },
  // 美搭小程序跳转
  goMeita() {
    wx.navigateToMiniProgram({
      appId: 'wx0115d6a0eef80e3a',//小程序appid
      path: 'pages/home/main/index',//跳转关联小程序app.json配置里面的地址
      extraData: {
        foo: 'bar'
      },
     //**重点**要打开的小程序版本，有效值 develop（开发版），trial（体验版），release（正式版）
      envVersion: 'release',
      success(res) {
        // 打开成功
      }
    })
  },
  encyclopediaDetail(e){
    let id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '/packagBuy/pages/found/contentDetail/contentDetail?id='+id,
    })
  },
  // 全屋定制列表
  wholeCustom() {
    wx.navigateTo({
      url: '/packagBuy/pages/marketing/wholeCustom/wholeCustom'
    })
  },
  // 获取头部背景图
  getTopTheme() {
    app.reqFun.requestJson('POST',configUrl.sysTheme + `/${'homeTop'}`,'',(res)=>{
      if(res.data.success==1){
        if (res.data.data) {
          let headBgimg = this.data.imgUrl + res.data.data.bgPic
          this.setData({
            headBgimg: headBgimg
          })
        } else {
          this.setData({
            headBgimg: this.data.bgimgUrl + 'headBgimg.png'
          })
        }
      }
    })
  },
  // 获取秒杀主题色
  getSeckillTheme() {
    app.reqFun.requestJson('POST',configUrl.sysTheme + `/${'homeSeckill'}`,'',(res)=>{
      if(res.data.success==1){
        if (res.data.data) {
          let seckillBgimg = this.data.imgUrl + res.data.data.bgPic
          this.setData({
            seckillBgimg: seckillBgimg
          })
          if (res.data.data.subTitleFontColor) {
            this.setData({
              seckillsubColor: res.data.data.subTitleFontColor
            })
          }
        } else {
          this.setData({
            seckillBgimg: this.data.bgimgUrl + 'seckillBgimg.png?01'
          })
        }
      }
    })
  },
  // 获取尖货爆款模块主题色
  getHotTheme() {
    app.reqFun.requestJson('POST',configUrl.sysTheme + `/${'homeHot'}`,'',(res)=>{
      if(res.data.success==1){
        if (res.data.data) {
          let hotmoneyBgimg = this.data.imgUrl + res.data.data.bgPic
          let titleText = res.data.data.titleText.split('&%&')
          let subTitleText = res.data.data.subTitleText.split('&%&')
          let hotmoneyData = [{name: titleText[0], id: 0, sub: subTitleText[0]}, {name: titleText[1], id: 1, sub: subTitleText[1]}]
          // 全屋购数据判断是否显示第三个标题
          if (this.data.appSmsActivities) {
            if (titleText[2]) {
              hotmoneyData = [{name: titleText[0], id: 0, sub: subTitleText[0]}, {name: titleText[1], id: 1, sub: subTitleText[1]}, {name: titleText[2], id: 2, sub: subTitleText[2]}]
            } else {
              hotmoneyData = [{name: titleText[0], id: 0, sub: subTitleText[0]}, {name: titleText[1], id: 1, sub: subTitleText[1]}, {name: '全屋购', id: 2, sub: '搭配更省心'}]
            }
          }
          // 截取副标题多余文字,最多显示6个
          console.log('hotmoneyData', hotmoneyData)
            for (var i = 0; i < hotmoneyData.length; i++) {
              if (hotmoneyData[i].sub !== '' && hotmoneyData[i].sub !== undefined && hotmoneyData[i].sub !== null) {
                if (hotmoneyData[i].sub.length > 6) {
                  hotmoneyData[i].sub = hotmoneyData[i].sub.substr(0, 6)
                }
                if (hotmoneyData[0].name == '' || hotmoneyData[0].name == null  || hotmoneyData[0].name == undefined) {
                  hotmoneyData[0].name = '尖货爆款'
                }
                if (hotmoneyData[0].sub == '' || hotmoneyData[0].sub == null  || hotmoneyData[0].sub == undefined) {
                  hotmoneyData[0].sub = '精选好货推荐'
                }
                if (hotmoneyData[1].name == '' || hotmoneyData[1].name == null  || hotmoneyData[1].name == undefined) {
                  hotmoneyData[1].name = '新品首发'
                }
                if (hotmoneyData[1].sub == '' || hotmoneyData[1].sub == null  || hotmoneyData[1].sub == undefined) {
                  hotmoneyData[1].sub = '新品追潮流'
                }
              }
            }
          this.setData({
            hotmoneyBgimg: hotmoneyBgimg || this.data.bgimgUrl+'hotmoneyBgimg.png',
            hotColor: {
              subTitleFontColor: res.data.data.subTitleFontColor,
              subTitleSelectFontBgColor: res.data.data.subTitleSelectFontBgColor,
              subTitleSelectFontColor: res.data.data.subTitleSelectFontColor,
              titleFontColor: res.data.data.titleFontColor
            },
            hotmoneyData: hotmoneyData
          })
        } else {
          this.setData({
            hotmoneyBgimg: this.data.bgimgUrl+'hotmoneyBgimg.png',
          })
          if (this.data.appSmsActivities) {
            this.setData({
              hotmoneyData: [{name: '尖货爆款', id: 0, sub: '精选好货推荐'}, {name: '新品首发', id: 1, sub: '新品追潮流'},{name: '全屋购', id: 2, sub: '搭配更省心'}],
            })
          }
        }
      }
    })
  }
})
